﻿using System;
using System.Linq;
using System.Collections.Generic;
using System.Text;
using System.Xml.Linq;
using System.IO;
using System.Windows;
using System.Windows.Forms;

namespace Saturn.App.FormOper
{

    public class FrmSetOper
    {
        //*****************以下为操作xml代码逻辑
        public string file = System.IO.Path.GetDirectoryName(System.Reflection.Assembly.GetExecutingAssembly().GetName().CodeBase) + "\\RoleSet.xml";

        /// <summary>
        /// 读取收获机构的配置 xml
        /// </summary>
        /// <returns></returns>
        public Dictionary<string, string> ReadXml()
        {
            if (!File.Exists(file))
            {
                MessageBox.Show("配置文件丢失，请联系管理员！");
                return null;
            }

            Dictionary<string, string> disc = new Dictionary<string, string>();

            XDocument xmlFile = XDocument.Load(file);
            var select = from c in xmlFile.Elements("root").Elements("role")
                         select new { key = c.Attribute("name"), value = c.Value };

            if (select.Count() > 0)
            {

                foreach (var item in select)
                {
                    disc.Add(item.key.Value, item.value);
                }
            }

            return disc;
        }


    }
}
